package com.rw.map.service;

import java.util.Date;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;

import com.rw.map.dao.NavigateDao;
import com.rw.map.utils.DateUtils;
import com.rw.map.websocket.WebSocketServer;

/**
 * 
 * @author forest
 *
 */
@EnableScheduling
@Configuration      
public class TaskService {
	
	@Autowired
	private WebSocketServer webSocketServer;

	
	@Autowired
	private NavigateService navigateService;

	@Autowired
	private NavigateDao navigateDao;
	
	/**
	 * 每隔5秒推送一次实时数据
	 * 
	 */
	@Scheduled(cron = "*/5 * * * * ?")
	public void pushNavigate() {
		try {
			webSocketServer.broadCastNavigateInfo();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	@Scheduled(cron = "*/5 * * * * ?")
	public void getNavigate() {
		try {
			//navigateService.saveCameraData();
		} catch (Exception e) {
			e.printStackTrace();
		}
		
	}
	
	
	/**
	 * 每天凌晨执行删除历史数据
	 */
	@Scheduled(cron = "0 0 0 * * ?")
	public void delHistory() {
		Date lastTime = DateUtils.getDateByAddDay(-31);
		//navigateDao.delLinesHistory(lastTime);
		//navigateDao.delPersonHistory(lastTime);
	}
}
